package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Simpleuser;
import com.ruoyi.system.service.ISimpleuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 普通用户管理Controller
 *
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/simpleuser")
public class SimpleuserController extends BaseController
{
    @Autowired
    private ISimpleuserService simpleuserService;

    /**
     * 查询普通用户管理列表
     */
    @RequiresPermissions("system:simpleuser:list")
    @GetMapping("/list")
    public TableDataInfo list(Simpleuser simpleuser)
    {
        startPage();
        List<Simpleuser> list = simpleuserService.selectSimpleuserList(simpleuser);
        return getDataTable(list);
    }


    /**
     * 获取普通用户管理详细信息
     */
    @RequiresPermissions("system:simpleuser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(simpleuserService.selectSimpleuserById(id));
    }

    /**
     * 新增普通用户管理
     */
    @RequiresPermissions("system:simpleuser:add")
    @Log(title = "普通用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Simpleuser simpleuser)
    {
        return toAjax(simpleuserService.insertSimpleuser(simpleuser));
    }

    /**
     * 修改普通用户管理
     */
    @RequiresPermissions("system:simpleuser:edit")
    @Log(title = "普通用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Simpleuser simpleuser)
    {
        return toAjax(simpleuserService.updateSimpleuser(simpleuser));
    }

    /**
     * 删除普通用户管理
     */
    @RequiresPermissions("system:simpleuser:remove")
    @Log(title = "普通用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(simpleuserService.deleteSimpleuserByIds(ids));
    }



    /**
     * 导入会员订单管理数据
     */
    @RequiresPermissions("system:simpleuser:import")
    @Log(title = "提现订单管理", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
    {
        ExcelUtil<Simpleuser> util = new ExcelUtil<Simpleuser>(Simpleuser.class);
        List<Simpleuser> SimpleuserList = util.importExcel(file.getInputStream());
        simpleuserService.importSimpleuser(SimpleuserList);
        return success();
    }

    /**
     * 导出普通用户管理列表
     */
    @RequiresPermissions("system:simpleuser:export")
    @Log(title = "普通用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Simpleuser simpleuser)
    {
        List<Simpleuser> list = simpleuserService.selectSimpleuserList(simpleuser);
        ExcelUtil<Simpleuser> util = new ExcelUtil<Simpleuser>(Simpleuser.class);
        util.exportExcel(response, list, "普通用户管理数据");
    }

}
